//    Copyright (C) Kherty.  All rights reserved.
using System;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Pivot
{
    internal class Location : IOfficeXmlSerializable
    {
        private string _ref;
        internal string Ref { get { return _ref; } }
        private int _firstDataRow;
        private int _firstDataCol;
        private int _rowPageCount;
        private int _colPageCount;
        private int _firstHeaderRow;

        public void ReadXml(ReadContext context)
        {
            using (var c = context.Read("location"))
            {
                _ref = c.GetString("ref");
                _firstHeaderRow = c.GetUIntegerAsInteger("firstHeaderRow");

                _firstDataRow = c.GetUIntegerAsInteger("firstDataRow");
                _firstDataCol = c.GetUIntegerAsInteger("firstDataCol");
                _rowPageCount = c.GetOptionalInteger("rowPageCount", 0);
                _colPageCount = c.GetOptionalInteger("colPageCount", 0);
            }

        }

        public void WriteXml(WriteContext context)
        {
            using (var c = context.Write("location"))
            {
                c.SetString("ref", _ref);
                c.SetUIntegerAsInteger("firstHeaderRow", _firstHeaderRow);
                c.SetInteger("firstDataRow", _firstDataRow);
                c.SetInteger("firstDataCol", _firstDataCol);
                c.SetOptionalInteger("rowPageCount", _rowPageCount, 0);
                c.SetOptionalInteger("colPageCount", _colPageCount, 0);
            }
        }
    }
}